package com.ruslan.magaz.web;

import java.io.IOException;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruslan.magaz.domain.Customer;
import com.ruslan.magaz.domain.Role;
import com.ruslan.magaz.domain.User;
import com.ruslan.magaz.service.RoleService;
import com.ruslan.magaz.service.UserService;

@Controller
@RequestMapping("/role")
public class RoleController {
	
	@Autowired
	private UserService userService;
	

	 
	 @RequestMapping(value="add")
	    public @ResponseBody
		void addRole(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{
		 
	            //HttpServletRequest httpReq = (HttpServletRequest) req;
//	            HttpSession session = req.getSession(true);
//	            int currentUserId = (Integer) session.getAttribute("userId");
//	            User user = userService.getUserById(currentUserId);
	            Role role =  new Role();
	            role.setRoleName("administrator");
	            userService.addRole(role);
		  }
	 
	 @RequestMapping(value="edit")
	    public @ResponseBody
		void editRole(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{
		        
	            Role role = new Role();
	            role.setRoleId(2);
	            role.setRoleName("admin");
	            userService.editRole(role);
		  }
	 
	 @RequestMapping(value="delete")
	    public @ResponseBody
		void deleteRole(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{

		 		Role role = userService.getRoleById(2);
	            userService.removeRole(role);
		  }
	 
	 

}



